<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="lg" :title="title" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <div class="card card-custom gutter-b example example-compact" id="tableJumpRulesSelectBody">
                
                <div class="card-body">
                    <!--查询条件-->
                    <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                        <div class="m-portlet__body">
                            <div class="form-group m-form__group row">                               
                                <b-button :pressed="false" variant="btn btn-light font-weight-bold mr-2"
                                    @click="resetAll()"> <span><span>刷新</span></span></b-button>
                                <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="doSelect">
                                    <i class="icon-xl fas fa-save"></i> 确认
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <el-table style="width: 100%" stripe border @selection-change="handleSelectionChange" highlight-current-row
                    :data="dataList">
                    <!-- 复选框 -->
                    <el-table-column type="selection" width="40"></el-table-column>
                    <el-table-column label="序号" width="60">
                        <template slot-scope="scope">
                            {{ scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column align="left" prop="nodeName" width="100" show-overflow-tooltip  label="节点名称" min-width="60"></el-table-column>
                    <el-table-column align="left" prop="nodeId" show-overflow-tooltip label="节点编号"></el-table-column>
                </el-table>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            currentRow:null,
            callBackData:{},
            searchForm: { },
            dataList: [],
            sels: [], //当前选框选中的值           
            title: '节点选择器',
        }
    },
    components: {

    },
    props: {

    },
    watch: {

    },
    mounted() {
    },
    methods: {
        showModal(row,index,data) {
            this.$refs['my-modal'].show();
            this.currentRow = row;
            this.initList();
            this.callBackData.index = index;
            this.callBackData.data = data;
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        initList() {
            showWating({ renderBody: "tableJumpRulesSelectBody" });
            var url = "";
            var mountsId = this.currentRow.mountsId;
            var hid_ = this.currentRow.hid_;            
            if((null == mountsId || '' == mountsId) && null != hid_){//说明非挂靠
                url = process.env.VUE_APP_WORKFLOW_API+'/lcDeploymentHis/userTasks/'+hid_;
            }else{
                url = process.env.VUE_APP_WORKFLOW_API+'/lcProcess/userTasks/'+mountsId;
            }
            var params = {};
            params.searchJson = JSON.stringify(this.searchForm);//为form元素     
            apiUtil.post(url, params).then(({ data }) => {
                this.dataList = data.data;//给结果集赋值
            });
        },
        handleSelectionChange(sels) {//获取选中的值
            this.sels = sels;
        },
        doSelect() {
            if (this.sels.length === 0) {
                handleAlert("请选择", "warning", 3)
                return;
            }
            this.$confirm("确认选择?", "提示", { type: "warning", }).then(() => {
                this.hideModal();//关闭窗体
                this.$emit("change", this.sels,this.callBackData);//组件传值，即向父级模态框中传递值，采用change方式，目标刷新主列表使用
                // 根据后台想要的参数格式选择          
            }).catch(() => { });//注意这里，这里是重点！！！;        
        },       
        search() {
            this.pageNo = 1;       // 更新当前的页
            this.initList();          // 按新的pageNo和pageSize进行查询
        },
        resetAll() {
            Object.assign(this.$data.searchForm, this.$options.data().searchForm);
            this.search();
        },
    }
}
</script>